import Vue from 'vue'
import VueRouter from 'vue-router'
import store from '@/store'
Vue.use(VueRouter)
const routes = [
  {
    path: '/',
    name: 'layout',
    component: () => import('../views/layout.vue'),
    redirect:'/home',
    children:[
      {
        path: 'home',
        name: 'home',
        meta:{
          title:'首页'
         },
        component: () => import('../views/pages/home'),
      },
      {
        path: 'user',
        name: 'user',
        meta:{
          title:'员工'
         },
        component: () => import('../views/pages/user'),
      },
      {
        path: 'approvals',
        name: 'approvals',
        meta:{
          title:'审批'
         },
        component: () => import('../views/pages/approvals'),
      },
      // department
      {
        path: 'department',
        name: 'department',
        meta:{
          title:'部门'
         },
        component: () => import('../views/pages/department'),
      },
      {
        path: 'limit',
        name: 'limit',
        meta:{
          title:'权限'
         },
        component: () => import('../views/pages/limit'),
      },
      {
        path:'/approvals/leaveApproval',
        name:'申请请假',
        component: () => import('../views/pages/leaveApproval.vue'),
    
      },
      // leaveApproval
      {
        path:'/user/detail',
        name:'员工信息',
        component: () => import('../views/pages/detail.vue'),
    
      },
      // users/approvals
      {
        path:'users/approvals',
        name:'用户审批',
        component: () => import('../views/pages/usersapprovals'),
    
      },
      {
        path: 'company',
        name: 'company',
        meta:{
          title:'公司'
         },
        component: () => import('../views/pages/company.vue'),
      },
    ]
  },
  {
    path:'/login',
    name:'login',
    component: () => import('../views/pages/login.vue'),

  },
 
  
]


const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
router.beforeEach((to,from,next)=>{
  
  // store.dispatch('gupdataToken')
  if(to.path=='/login') return next()
  else{
    const tokenStr = localStorage.getItem('RZtoken')
    if(tokenStr===''){
      return next('/login')
    }
    next()
  }
})
export default router
